home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-10-01 | 8.3 KB | 233 lines | [TEXT/MPS ] |
- //
- // atom2.c
- //
- // Demonstration of a format2 action atom and compatibility with
- // Installer Engine 4.1.
- //
- // Under Installer 4.0.3, a dialog is provided that allows the
- // user to select the return value for the action atom.
- //
- // Scriptwriters should be aware that the return values
- // and the actions that they invoke from the installer
- // are different depending on which format of action atom
- // is being used.
- //
- // It is recommended that the constants
- // 'kActionAtomResultFatalError' <= -1
- // 'kActionAtomResultContinue' <= 0
- // 'kActionAtomResultCancel' <= 1
- // be used when working with format2 action atoms.
- // These constants are defined in "ActionAtomHeader.h"
- // and are designed for use with format2 action atoms.
- //
- // NOTE: Displaying dialogs from within action atoms and other
- // code resources is discouraged. Installer scripts that
- // display dialogs from within code resources will not work
- // when running under Installer Engine 4.1. This example shows
- // you how you can write action atom code that will display a
- // dialog under Installer 4.0.3 and still be compatible with
- // Installer Engine 4.1. For more information on script
- // compatibility with Installer Engine 4.1 see the "Engine 4.1
- // Compatiblity Issues" document in the Installer 4.1 folder of
- // the Installer SDK.
- //
- // Additionally, this example completely ignores good user
- // interface design practices for the purpose of demonstrating the
- // installer in regards to return values from an action atom.
- //
- // Copyright 1993-1996, Apple Computer, Inc., All Rights Reserved
- //
-
-
- #include <Traps.h>
- #include <Types.h>
- #include <dialogs.h>
- #include <TextUtils.h>
-
- // these line has been added for Wasabi Installer Debugger support
- #include "ActionHandlerHeader.h"
-
- // this line replaces #include "ActionAtomHeader.h" used in previous 4.0.3 action atoms
- #include "InstallerScript.h"
-
- // this is needed for highlighting the default button in dialog
- pascal OSErr SetDialogDefaultItem ( DialogPtr theDialog,
- short newItem ) = {0x303C,0x0304,0xAA68};
-
- // this is used to print one line out to the Wasabi Installer Debugger
- void PrintLine( InstallerCallBackUPP pCallBackProcPtr, Str255 pParam0, Str255 pParam1, Str255 pParam2, Str255 pParam3 );
-
- // print the parameter block record information to Wasabi Installer Debugger
- void PrintAAParamBlock( ActionAtom2PBPtr atomRecPtr );
-
- // NOTE: The name of this function 'ActionAtomFormat2' should
- // match that specified in the -m option for the line in the
- // makefile that compiles this action atom.
- ActionAtomResult ActionAtomFormat2( ActionAtom2PBPtr atomRecPtr )
- {
-
- DialogPtr theDialog; // for dialog
- OSErr theOSError = 0; // for errors
-
- short theItemHit; // gets user response from ModalDialog()
- short iType; // gets control type from GetDItem()
- Handle iHandle; // gets control handle from GetDItem()
- Rect iRect; // gets control rect from GetDItem()
-
- short currRadioButton = 2; // current selected radio button
- short gettingUserResponse = true; // flag for while loop
-
- short theStatus = 0; // value to return from function
-
- // print the parameter block record information to Wasabi Installer Debugger
- PrintAAParamBlock( atomRecPtr );
-
- // retrieve DLOG/DITL 130 from compiled resource script
- theDialog = GetNewDialog( 130, nil, (WindowPtr) -1 );
-
- // Installer Engine 4.1 will indicate that a window cannot be displayed by
- // patching GetNewDialog and returning NULL.
- if( theDialog != NULL )
- {
- // We are running with Installer 4.0.3
- // Display the dialog.
-
- // activate OK button when enter or return key is pressed
- theOSError = SetDialogDefaultItem( theDialog, 1 );
-
- // set up the radio button group ( controls 2 - 4 )
- GetDItem( theDialog, 2, &iType, &iHandle, &iRect);
- SetCtlValue( (ControlHandle) iHandle, 1 );
-
- GetDItem( theDialog, 3, &iType, &iHandle, &iRect);
- SetCtlValue( (ControlHandle) iHandle, 0 );
-
- GetDItem( theDialog, 4, &iType, &iHandle, &iRect);
- SetCtlValue( (ControlHandle) iHandle, 0 );
-
- // select the new dialog
- SelectWindow( (WindowPtr) theDialog );
-
- // show the new dialog
- ShowWindow( (WindowPtr) theDialog );
-
- // keep getting response from user until
- // the OK is activated in the new dialog
- gettingUserResponse = true;
- while ( gettingUserResponse )
- {
- // get user selection from the new dialog
- ModalDialog( nil, &theItemHit );
-
- switch ( theItemHit )
- {
- // first control is the OK key
- case( 1 ) :
- // exit loop
- gettingUserResponse = false;
- break;
-
- // all other controls in dialog are radio buttons
- default :
- // continue with loop
- gettingUserResponse = true;
-
- // if the radio button selection changed
- if ( currRadioButton != theItemHit )
- {
- // turn previous radio button off
- GetDItem( theDialog, currRadioButton, &iType, &iHandle, &iRect);
- SetCtlValue( (ControlHandle) iHandle, 0 );
-
- // turn current radio button on
- GetDItem( theDialog, theItemHit, &iType, &iHandle, &iRect);
- SetCtlValue( (ControlHandle) iHandle, 1 );
-
- // save current radio button choice
- currRadioButton = theItemHit;
- }
- break;
- }// switch
-
- }// while
-
- // get rid of the new dialog
- DisposDialog( theDialog );
-
- // select a value to return from this function according to
- // which radio button was selected in the dialog
- switch ( currRadioButton )
- {
- // return 0
- case( 2 ) : theStatus = kActionAtomResultContinue; // user selected return 0
- break;
-
- // return 1
- case( 3 ) : theStatus = kActionAtomResultCancel; // user selected return 1
- break;
-
- // return -1
- case( 4 ) : theStatus = kActionAtomResultFatalError;// user selected return -1
- break;
- }
-
- // return value selected by user in dialog
- return( theStatus );
- }// if theDialog != NULL
- else
- {
- // We are running under Installer Engine 4.1, which doesn't interact with user.
- // Do default action here rather than trying to display a dialog.
- // Let's say the default action for this example is to return kActionAtomResultContinue.
-
- return (kActionAtomResultContinue);
- }
- }
-
- // shoot one line of text out to the Wasabi Installer Debugger
- void PrintLine( InstallerCallBackUPP pCallBackProcPtr, Str255 pParam0, Str255 pParam1, Str255 pParam2, Str255 pParam3 )
- {
- long theResult;
- RegisterScriptAction( pCallBackProcPtr, kDebuggingAction, kGenericDebugActID, pParam0, pParam1, pParam2, pParam3, &theResult );
- }
-
- // print a series of formatted lines describing the parameter block
- // received by the action atom out to the Wasabi Installer Debugger
- void PrintAAParamBlock( ActionAtom2PBPtr atomRecPtr )
- {
- Str255 numStr;
-
- PrintLine( atomRecPtr->fCallBackProcPtr, "\p\n", "\pParameter Block for Action Atom Format2...", "\p", "\p" );
-
- NumToString( atomRecPtr->fMessageID, numStr );
- PrintLine( atomRecPtr->fCallBackProcPtr, "\p", "\pfMessageID : ", numStr, "\p" );
-
- NumToString( (long) atomRecPtr->fStaticDataHdl, numStr );
- PrintLine( atomRecPtr->fCallBackProcPtr, "\pfStaticDataHdl : ", numStr, "\p", "\p" );
-
- NumToString( (long) atomRecPtr->fTargetVRefNum, numStr );
- PrintLine( atomRecPtr->fCallBackProcPtr, "\pfTargetVRefNum : ", numStr, "\p", "\p" );
-
- NumToString( (long) atomRecPtr->fTargetFolderDirID, numStr );
- PrintLine( atomRecPtr->fCallBackProcPtr, "\pfTargetFolderDirID : ", numStr, "\p", "\p" );
-
- NumToString( (long) atomRecPtr->fSystemVRefNum, numStr );
- PrintLine( atomRecPtr->fCallBackProcPtr, "\pfSystemVRefNum : ", numStr, "\p", "\p" );
-
- NumToString( (long) atomRecPtr->fSystemBlessedDirID, numStr );
- PrintLine( atomRecPtr->fCallBackProcPtr, "\pfSystemBlessedDirID : ", numStr, "\p", "\p" );
-
- NumToString( (long) atomRecPtr->fRefCon, numStr );
- PrintLine( atomRecPtr->fCallBackProcPtr, "\pfRefCon : ", numStr, "\p", "\p" );
-
- NumToString( (long) atomRecPtr->fDoingInstall, numStr );
- PrintLine( atomRecPtr->fCallBackProcPtr, "\pfDoingInstall : ", numStr, "\p", "\p" );
-
- NumToString( (long) atomRecPtr->fDidLiveUpdate, numStr );
- PrintLine( atomRecPtr->fCallBackProcPtr, "\pfDidLiveUpdate : ", numStr, "\p", "\p" );
-
- NumToString( (long) atomRecPtr->fInstallerTempDirID, numStr );
- PrintLine( atomRecPtr->fCallBackProcPtr, "\pfInstallerTempDirID : ", numStr, "\p", "\p\n" );
-
- }
-